package com.jingluo.action;

import com.jingluo.entity.User;
import com.jingluo.service.UserBiz;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import java.util.Map;

public class UserAction extends ActionSupport{

	private String name;
	private String password;
	private String message;
	
	// 定义业务接口属性
	private UserBiz userBiz;
	//定义setter方法,方法名应和Spring配置文件中业务Bean的名称相匹配
	public void setUserBiz(UserBiz userBiz) {
		this.userBiz = userBiz;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}	

	public String login(){
		
		User user = userBiz.login(name, password);
		ActionContext ac = ActionContext.getContext();
		if(name == null || name.equals("")){
			this.setMessage("登录失败，请检查用户名和密码是否正确");
			return "login_input";
		}
		if(password == null || password.equals("")){
			this.setMessage("登录失败，请检查用户名和密码是否正确");
			return "login_input";
		}		
		Map session = ac.getSession();
		if(null != user){
			session.put("login", user);				
			return "login_success";
		}
		
		this.setMessage("登录失败，请检查用户名和密码是否正确");
		
		return "login_input";
	}
	
}
